package ac.snu.cares.elgger.database;

import java.io.File;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class StateDBHelper extends SQLiteOpenHelper {

	public String TABLE_NAME = null;

	public final static String EVENT_ID = "id";
	public final static String OCCUR_TIME = "time";
	public final static String EVENT_DESCRIPTION = "desc";

	public StateDBHelper(Context context, String tableName, int version) {
		super(context, context.getExternalFilesDir(null) + File.separator
				+ tableName + ".db", null, version);
		this.TABLE_NAME = tableName;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String DATABASE_CREATE = "create table " + TABLE_NAME + " (" + EVENT_ID
				+ " integer primary key autoincrement, " + OCCUR_TIME
				+ " text not null, " + EVENT_DESCRIPTION + " text);";
		db.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}
}